import 'package:flutter/material.dart';
import 'package:xiongan_app_yy/common/user_singleton.dart';
import 'package:xiongan_app_yy/entrys/rp/wait_task_count_entity.dart';
import 'package:xiongan_app_yy/net/internet_api.dart';
import 'package:xiongan_app_yy/pages/common/LoadBuilder.dart';

//任务待办
class ChildrenTabThree extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return ChildrenTabThreeState();
  }
}

class ChildrenTabThreeState extends State<ChildrenTabThree> {
  bool show = true;
  bool InterfaceOne = false;
  bool InterfaceTwo = false;
  Map<String, dynamic> mapOne = Map();
  Map<String, dynamic> mapTwo = Map();
  WaitTaskCountDatas datas = WaitTaskCountDatas();

  @override
  void initState() {
    super.initState();
    getData();
  }

  @override
  Widget build(BuildContext context) {
    return LoadBuilder(
        visibility: show,
        builder: RefreshIndicator(
          child: ListView(
            children: <Widget>[
              ItemCounter("待审批预约", mapTwo["unApprovalQty"], () {
                Navigator.pushNamed(context, '/pendingApprovalPage');
              }, 0),
              ItemCounter("物流商响应审批", mapOne["isAcceptQty"], () {
                Navigator.pushNamed(context, '/logisticsResponsePage');
              }, 1),
              ItemCounter("待评价配送任务", mapOne["deliveryEndQty"], () {
                Navigator.pushNamed(context, '/notEvaluatedPage');
              }, 1),
            ],
          ),
          onRefresh: getData,
        ));
  }


  Future getData() async {
    show = true;
    InternetAPI.getInstance().get("/TMS/MiDeliveryTask/GetTaskQty",
            (data) {
      InterfaceOne=true;
      mapOne=data;
      if(InterfaceTwo==true){
        setState(() {
          show = false;
        });

      }
        }, params: {
          'warehouseid': DataSingleton().warehouseChoice.id,
          'tenantId': DataSingleton().Data.tenantId,
        });
    InternetAPI.getInstance().get("/OMS/MiTaskApproval/GetTodayApprovalQty",
            (data) {
              InterfaceTwo=true;
              mapTwo=data;
              if(InterfaceOne==true){
                setState(() {
                  show = false;
                });
              }
        }, params: {
          'warehouseid': DataSingleton().warehouseChoice.id,
          'tenantId': DataSingleton().Data.tenantId,
          "workuserid": DataSingleton().Data.id,
        });
  }


}

class ItemCounter extends StatelessWidget {
  String name;
  int counter;
  Function onTap;
  double top;

  ItemCounter(this.name, this.counter, this.onTap, this.top);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: Container(
        color: Colors.white,
        padding: EdgeInsets.all(12),
        margin: EdgeInsets.only(top: top),
        child: Row(
          children: <Widget>[
            Expanded(
                child: Text(
                  name,
                  style: TextStyle(color: Color(0xff323232), fontSize: 16),
                )),
            Text("【${counter}】",
                style: TextStyle(color: Color(0xff00A5F1), fontSize: 16)),
            Container(
              width: 16,
              height: 10,
              child: Image.asset("assets/images/arrow.png"),
            )
          ],
        ),
      ),
      onTap: onTap,
    );
  }
}